package com.example.springboottestgit.service.instruction;

import com.example.springboottestgit.bean.InstructData;
import com.example.springboottestgit.common.RunNum;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;


@Service
public class CountService {

    public List<InstructData> getInstructData() {
        List<InstructData> list = new ArrayList<>();
        for (int i = 0; i < RunNum.A; i++) {
            list.add(mul1());
            list.add(mul());
            list.add(mul1());
        }
        return list;
    }

    //乘法
    public InstructData mul() {
        Random random = new Random();
        int a = 1000;

        int x = random.nextInt(a);
        int y = random.nextInt(a);
        int z = x * y;

        String instruction = "请计算x乘以y等于多少";
        String input = "";
        String output = "计算过程:x×y=z 所以，结果是z。";

        instruction = instruction.replace("x", x + "").replace("y", y + "");
        output = output.replace("z", z + "").replace("x", x + "").replace("y", y + "");

        InstructData demo = new InstructData();
        demo.setInstruction(instruction);
        demo.setInput("");
        demo.setOutput(output);
        return demo;
    }


    public InstructData mul1() {
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        double minValue = 10;
        double maxValue = 1000;
        double a = minValue + Math.random() * (maxValue - minValue);
        double b = minValue + Math.random() * (maxValue - minValue);

        double x = Double.parseDouble(decimalFormat.format(a));
        double y = Double.parseDouble(decimalFormat.format(b));
        double z = x * y;

        String instruction = "请计算x乘以y等于多少";
        String input = "";
        String output = "计算过程:x×y=z 所以，结果是z。";

        instruction = instruction.replace("x", x + "").replace("y", y + "");
        output = output.replace("z", z + "").replace("x", x + "").replace("y", y + "");

        InstructData instructData = new InstructData();
        instructData.setInstruction(instruction);
        instructData.setInput("");
        instructData.setOutput(output);
        return instructData;
    }

}
